home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / plan / src / pixmap.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  124 lines

  1. /*
  2.  * Initializes all pixmaps used in the program. Only called once.
  3.  *
  4.  *    init_pixmaps()
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <Xm/Xm.h>
  9. #include <X11/StringDefs.h>
  10. #include "cal.h"
  11.  
  12. #include "bm_recycle.h"
  13. #include "bm_advance.h"
  14. #include "bm_message.h"
  15. #include "bm_script.h"
  16. #include "bm_group.h"
  17. #include "bm_private.h"
  18. #include "bm_icon.h"
  19. #include "bm_iconsub.h"
  20.  
  21.  
  22. static char blank_bits[] =
  23.     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
  24.  
  25. extern void        get_rsrc();
  26. extern char        *mktimestring();
  27. extern time_t        get_time();
  28.  
  29. extern struct config    config;        /* global configuration data */
  30. extern Display        *display;    /* everybody uses the same server */
  31. extern char        *progname;    /* argv[0] */
  32. extern Widget        toplevel;    /* top-level shell for icon name */
  33. extern Pixel        color[NCOLS];    /* colors: COL_* */
  34. Pixmap            pixmap[NPICS];    /* common symbols */
  35.  
  36.  
  37. static char *pics[NPICS] = {
  38.     advance_bits, recycle_bits, message_bits, script_bits,
  39.     /* group_bits, private_bits, blank_bits, <<< not implemented yet */
  40.     blank_bits, private_bits, blank_bits
  41. };
  42.  
  43. static int pix_width[NPICS] = {
  44.     advance_width, recycle_width, message_width, script_width,
  45.     group_width, private_width, recycle_width
  46. };
  47.  
  48. static int pix_height[NPICS] = {
  49.     advance_height, recycle_height, message_height, script_height,
  50.     group_height, private_height, recycle_height
  51. };
  52.  
  53.  
  54. /*
  55.  * intialize pixmaps for mode buttons
  56.  */
  57.  
  58. init_pixmaps()
  59. {
  60.     int            p;
  61.     Colormap        cmap;
  62.     XColor            rgb;
  63.     char            *c;
  64.     BOOL            failed;
  65.  
  66.     cmap = DefaultColormap(display, DefaultScreen(display));
  67.     get_rsrc(&c, "background", "Background", XtRString);
  68.     if (failed = !XParseColor(display, cmap, c, &rgb))
  69.         fprintf(stderr, "unknown color \"background\" = %s\n", c);
  70.     if (failed |= !XAllocColor(display, cmap, &rgb))
  71.         fprintf(stderr, "can't allocate color \"background\"\n");
  72.     for (p=0; p < NPICS; p++)
  73.         if (!(pixmap[p] = XCreatePixmapFromBitmapData(display,
  74.                 DefaultRootWindow(display),
  75.                 pics[p], pix_width[p], pix_height[p],
  76.                 color[COL_STD],
  77.                 failed ? color[COL_BACK] : rgb.pixel,
  78.                 DefaultDepth(display,DefaultScreen(display)))))
  79.             fatal("no memory for pixmaps");
  80. }
  81.  
  82.  
  83. /*
  84.  * set icon for the application or a shell.
  85.  */
  86.  
  87. set_icon(shell, sub)
  88.     Widget            shell;
  89.     int            sub;        /* 0=main, 1=submenu */
  90. {
  91.     Pixmap            icon;
  92.  
  93.     if (!config.noicon && !sub)
  94.         if (icon = XCreatePixmapFromBitmapData(display,
  95.                 DefaultRootWindow(display),
  96.                 sub ? iconsub_bits : icon_bits,
  97.                 icon_width, icon_height,
  98.                 WhitePixelOfScreen(XtScreen(shell)),
  99.                 BlackPixelOfScreen(XtScreen(shell)),
  100.                 DefaultDepth(display, DefaultScreen(display))))
  101.  
  102.             XtVaSetValues(shell, XmNiconPixmap, icon, NULL);
  103.  
  104.     print_icon_name();
  105. }
  106.  
  107.  
  108. /*
  109.  * change the name below the icon. Relies on <toplevel> from main(). Changing
  110.  * the icon title to the current time can bbe switched off because it prevents
  111.  * the screen saver from kicking in.
  112.  */
  113.  
  114. print_icon_name()
  115. {
  116.     time_t            tod;        /* current time-of-day */
  117.  
  118.     if (config.showicontime) {
  119.         tod = get_time() % 86400;
  120.         XtVaSetValues(toplevel, XmNiconName,
  121.                     mktimestring(tod, FALSE), NULL);
  122.     }    
  123. }
  124.